package com.haibei.activity.user;

import android.content.Intent;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.common.uitl.StringUtils;
import com.common.uitl.ValidateTool;
import com.haibei.R;
import com.haibei.activity.BaseHaibeiActivity;
import com.haibei.view.StageWheelView;
import com.haibei.view.StageWheelView.StageSelectListener;

public class RegistActivity1 extends BaseHaibeiActivity implements View.OnClickListener {

	private EditText mEditTextEmail;
	private EditText mEditTextNickName;
	private EditText mEditTextPassword;

	private static final int INT_GO_REGIST2 = 1000;

	public static String email = "";
	public static String userName = "";
	public static String password = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initView();
	}

	@Override
	public void initView() {
		setContentView(R.layout.activity_regist1);
		mEditTextEmail = findEditTextById(R.id.editTextEmail);
		mEditTextNickName = findEditTextById(R.id.editTextUserName);
		mEditTextPassword = findEditTextById(R.id.editTextPassword);

		findButtonById(R.id.buttonCancell).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				backFinish();
			}
		});
		findButtonById(R.id.buttonNext).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (checkValue()) {
					Intent i = new Intent();
					i.setClass(RegistActivity1.this, RegistActivity2.class);
					startActivityForResult(i, INT_GO_REGIST2);
				}
			}
		});
	}

	@Override
	public void onClick(View v) {
		int vid = v.getId();
		switch (vid) {
		case R.id.linearLayoutStateSelect:

			break;
		case R.id.linearLayoutCitySelect:

			break;
		default:
			break;
		}
	}

	private boolean checkValue() {

		if (!ValidateTool.checkEmail(getEmail())) {
			mEditTextEmail.setError("请输入正确的Email");
			// Tool.ToastShow(this, "请输入正确的Email");
			return false;
		} else {
			email = getEmail();
		}
		// /^[a-z0-9_-]{3,16}$/
		if (StringUtils.isEmpty(getNickName())) {
			mEditTextNickName.setError("请输入正确的用户名！");
			return false;
		} else {
			userName = getNickName();
		}

		if (StringUtils.isEmpty(getPassword()) || getPassword().length() < 6) {
			mEditTextPassword.setError("请输入至少6位密码！");
			return false;
		} else {
			password = getPassword();
		}

		return true;
	}

	private String getEmail() {
		String text = mEditTextEmail.getText().toString();
		return StringUtils.isEmpty(text) ? "" : text;
	}

	private String getNickName() {
		String text = mEditTextNickName.getText().toString();
		return StringUtils.isEmpty(text) ? "" : text;
	}

	private String getPassword() {
		String text = mEditTextPassword.getText().toString();
		return StringUtils.isEmpty(text) ? "" : text;
	}

	@Override
	public void backFinish() {
		super.backFinish();
	}

	@Override
	public void onActionModeFinished(ActionMode mode) {
		super.onActionModeFinished(mode);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		switch (requestCode) {
		case INT_GO_REGIST2:
			if (resultCode == RESULT_OK) {
				setResult(RESULT_OK);
				finish();
			}
			break;

		default:
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
}
